<?php include PATH_TPL."/admin/tpl.header.phtml"?>
<div class="main-container inner">
    <div class="main-content">
        <div class="container-fluid">
            <div class="row bt">
                <div class="col-lg-12 bg">
                    <ol class="breadcrumb">
                        <li class="active">
                            <i class="fa  fa-fw fa-reorder"></i>修改账号
                        </li>
                    </ol>
                </div>
            </div>
            <div id="page-wrapper">
                <div class="container-fluid col-md-7 col-sx-12">
                    <form method="post" enctype="multipart/form-data" name="myform">
                        <div class="form-group">
                            <label for="department"><strong>所在部门:</strong></label>                            
                            <select name="department" disabled>
                                <option value="0">请选择</option>
                                <?foreach($tDDatas as $tDRow){?>
                                <option value="<?=$tDRow['num']?>"><?=$tDRow['introduce']?></option>
                                <?}?>
                            </select>
                            <label for="name" style="margin-left:50px;" class="name"><strong>员工姓名:</strong></label>                            
                            <select name="w_id" disabled>
                                <option value="0">请选择</option>
                                <?foreach($tWData as $tWRow){?>
                                <option value="<?=$tWRow['id']?>"><?=$tWRow['name']?></option>
                                <?}?>
                            </select>
                            <label for="name" style="margin-left:50px;"><strong>员工所属角色:</strong></label>                            
                            <select name="role" disabled>
                                <option value="0">请选择</option>
                                <?foreach($tRDatas as $tRRow){?>
                                <option value="<?=$tRRow['num']?>"><?=$tRRow['introduce']?></option>
                                <?}?>
                            </select>
                        </div>
                        <div class="form-group">
                            <label for="name" class="department"><strong>管理部门</strong></label><br>                            
                        </div>
                        <div class="form-group">
                            <label for="name"><strong>账号名称</strong></label>                            <input type="text" placeholder="请输入邮箱" id="name" class="form-control" name="name" />
                        </div>
                        <div class="form-group">
                            <label for="passwd"><strong>初始密码</strong>(密码为6-16位数字、字母)</label>
                            <input type="text" placeholder="121212" id="passwd" class="form-control" name="passwd" value="121212" />
                        </div>
                        <button class="btn btn-primary demo_2" type="button" id="submit">修改</button>
                    </form>   
                </div>
                <div class="subviews">
                    <div class="subviews-container"></div>
                </div>
            </div>
            <!-- end: PAGE -->
        </div>
    </div>
</div>
<!-- end: MAIN CONTAINER -->
<script type="text/javascript" src="/plugins/jquery-ui-1.11.4/jquery-ui.min.js"></script>
 <script type="text/javascript" src="/plugins/medialog/mdialog.js"></script><!--medialog -->
 <script type="text/javascript" src="/plugins/medialog/zepto.min.js"></script><!--zepto -->
<script>
var w_id = '';
    //所在部门与姓名绑定显示
    $('select[name="department"]').on('change',function(){
        var department_id = $(this).val();
        $.get('/admin_admin/add',{department_id:department_id},function(obj){
            $('select[name="w_id"]').remove();
            if(obj.status == 1){
                var data = obj.data;
                var html = (
                    '<select name="w_id">'
                );
                $.each(data,function(key,row){
                    html += '<option value="'+row.id+'">'+row.name+'</option>';
                });
                html += '</select>';
                $('.name').after(html);
            }
        });
    });
    $('select[name="role"]').on('change',function(){
        var role = $(this).val();
        w_id = $('select[name="w_id"]').val();
        $.get('/admin_admin/add',{role:role,w_id:w_id},function(obj){
            if(obj.status == 1){
                var data = obj.data;
                $('input[name="department[]"]').remove();
                $('.introduce').remove();
                for(i in data){
                    $('.department').after('<input type="checkbox" name="department[]" value="'+data[i].num+'" style="margin-left:20px;"/><span class="introduce">'+data[i].introduce+'</span>');
                }
            }
        });
    });
    var id = <?=$pId?>;
    $.post('/admin_admin/edit',{id:id},function(obj){
        if(obj.status == 1){
            var data = obj.data[0];
            $('select[name="department"]').val(data.department);
            $('select[name="w_id"]').remove();
            var html = (
                '<select name="w_id">'
            );
            html += '<option value="'+data.w_id+'">'+data.name+'</option>';
            html += '</select>';
            $('.name').after(html);
            $('select[name="role"]').val(data.role);
            for(i in data.departments){
                $('.department').after('<input type="checkbox" name="department[]" value="'+run(data.departments[i])+'" style="margin-left:20px;" checked="checked"/><span class="introduce">'+data.departments[i]+'</span>');
            }
            $('input[name="name"]').val(data.username);
        }
    });
    $('#submit').click(function(){
        var data = $('form[name="myform"]').serialize();
        data += '&tId=<?=$pId?>';
        
        $.post('/admin_admin/edit',data,function(obj){
                cg_alert_edit(obj,'/admin_admin/','/admin_admin/edit?aid=<?=$pId?>');
        });
    });
    function run(data){
        if(data == '东三区'){
            return '1';    
        }else if(data == '西四区'){
            return '2';
        }else if(data == '本三区'){
            return '3';
        }else{
            return '4';
        }
    }
</script>

<?php include PATH_TPL."/admin/tpl.footer.phtml"?>
